package heapsort;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Writer {

	private FileWriter fw;
	private BufferedWriter bw;
	private File f;
	private int teller;

	public Writer() {
		try {
			f = new File( "sortedBestand.txt"  );
			fw = new FileWriter(f);
			bw = new BufferedWriter(fw);
			teller = 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void writeInt(int number) {
		try {
			bw.write(number + " ");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void close() {
		try {
			bw.close();
			fw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void writeSpace() {
		try {
			bw.write("\n");
			teller++;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public int getTeller() {
		return teller + 1; //ja +1. de laatste run word er niet bij geteld
	}

	public void writeArray(int[] array, int beginn) {
		for (int i = beginn; i < array.length - 1; i++) {
			try {
				bw.write(array[i] + " ");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
